<cfcomponent displayname="HibernateTest">  

  <cffunction name="runAllTests" access="public" returntype="void">
		<cfargument name="hibernateService" required="true">
		<cfset var hibernate = arguments.hibernateService />
		<cfset var testresults = structNew()>
		<cfscript>
			testresults["testAddProject"] = testAddProject(hibernate);
			testresults["testSaveObject"] = testSaveObject(hibernate);
			testresults["testSaveSubObject"] = testSaveSubObject(hibernate);
			testresults["testLoadComponent"] = testLoadComponent(hibernate);
			testresults["testLoadSaveComponent"] = testLoadSaveComponent(hibernate);
		</cfscript>
		
		<cfdump var="#testresults#"><cfabort />
		<cfreturn testresults />
  </cffunction>

  <cffunction name="testAddProject" access="public" returntype="any">
		<cfargument name="hibernateService" required="true">
		<cfset var hibernate = arguments.hibernateService />
		<cfset var testresults = structNew()>
		<cfset var project = createObject("component","hibernate.jndiexample.data.Projects").init() />
		<cfset project.setProjectName("Project" & randrange(1,100)) />
		<cfset project.setProjectTitle("ProjectTitle" & randrange(1,100)) />
		<cfset project.setProjectDescription("ProjectDescription" & randrange(1,100)) />
		<cfset project.setDateCreated(now()) />
		<cfset project.setDateModified(now()) />
		<cfset project.setProjectId(0) />
		<cfdump var="#project._getTO()#"><cfabort />
		<cfset project = hibernate.save("jndiexample.data.Projects",project) >
		<cfif project.getProjectId() neq 0>
			<cfreturn "success">
		</cfif>
  </cffunction>		

  <cffunction name="testAddProjectAndRelated" access="public" returntype="any">
		<cfargument name="hibernateService" required="true">
		<cfset var hibernate = arguments.hibernateService />
		<cfset var testresults = structNew()>
		<cfset var project = createObject("component","hibernate.jndiexample.data.Projectcomponents").init() />
		<cfset var projectComponent = createObject("component","hibernate.jndiexample.data.Projectcomponents").init() />
		<cfset projectComponent.setComponentName("wee") />
		<cfset projectComponent.setComponentDescription("wee") />
		<cfset projectComponent.setCreateUserId(3) />
		<cfset projectComponent.setComponentId(0) />
		<cfset projectComponent.setProjects(project) />
		<cfset projectComponent = hibernate.save("jndiexample.data.Projectcomponents",projectComponent) >
		<cfif projectComponent.getComponentId() neq 0>
			<cfreturn "success">
		</cfif>
  </cffunction>		


  <cffunction name="testSaveObject" access="public" returntype="any">
		<cfargument name="hibernateService" required="true">
		<cfset var hibernate = arguments.hibernateService />
		<cfset var testresults = structNew()>
		<cfset var project = hibernate.load("jndiexample.data.Projects",1) >
		<cfset var projectComponent = createObject("component","hibernate.jndiexample.data.Projectcomponents").init() />
		<cfset projectComponent.setComponentName("wee") />
		<cfset projectComponent.setComponentDescription("wee") />
		<cfset projectComponent.setCreateUserId(3) />
		<cfset projectComponent.setComponentId(0) />
		<cfset projectComponent.setProjects(project) />
		<cfset projectComponent = hibernate.save("jndiexample.data.Projectcomponents",projectComponent) >
		<cfif projectComponent.getComponentId() neq 0>
			<cfreturn "success">
		</cfif>
  </cffunction>		

  <cffunction name="testSaveSubObject" access="public" returntype="any">
		<cfargument name="hibernateService" required="true">
		<cfset var hibernate = arguments.hibernateService />
		<cfset var testresults = structNew()>
		<cfset var project = hibernate.load("jndiexample.data.Projects",1) >
		<cfset var projectComponent = createObject("component","hibernate.jndiexample.data.Projectcomponents").init() />
		<cfset projectComponent.setComponentName("wee") />
		<cfset projectComponent.setComponentDescription("wee") />
		<cfset projectComponent.setCreateUserId(3) />
		<cfset projectComponent.setComponentId(0) />
		<cfset projectComponent.setProjects(project) />
		<cfset projectComponent = hibernate.save("jndiexample.data.Projectcomponents",projectComponent) >
		<cfif projectComponent.getComponentId() neq 0>
			<cfreturn "success">
		</cfif>
  </cffunction>


  <cffunction name="testLoadComponent" access="public" returntype="any">
		<cfargument name="hibernateService" required="true">
		<cfset var hibernate = arguments.hibernateService />
		<cfset var testresults = structNew()>		
		<cfset var projectComponentBean = createObject("component","hibernate.jndiexample.data.Projectcomponents").init() />
		<cfset var project = hibernate.loadComponent("jndiexample.data.Projects",1) />
		<cfset var projectComponent = hibernate.loadComponent("jndiexample.data.Projectcomponents",5,projectComponentBean) />
<!---
 		<cfdump var="#projectComponent._getTO()#" />
 --->
		<cfif projectComponent.getComponentId() neq 0>
			<cfreturn "success">
		</cfif>
  </cffunction>

  <cffunction name="testLoadSaveComponent" access="public" returntype="any">
		<cfargument name="hibernateService" required="true">
		<cfset var hibernate = arguments.hibernateService />
		<cfset var testresults = structNew()>		
		<cfset var projectComponentBean = createObject("component","hibernate.jndiexample.data.Projectcomponents").init() />
		<cfset var project = hibernate.loadComponent("jndiexample.data.Projects",1) />
		<cfset var projectComponent = hibernate.loadComponent("jndiexample.data.Projectcomponents",5,projectComponentBean) />
		<cfset projectComponent.setComponentName("testLoadSaveComponent") />
		<cfset projectComponent.setComponentDescription("testLoadSaveComponent") />
		<cfset projectComponent.setCreateUserId(3) />
		<cfset projectComponent.setComponentId(0) />
		<cfset projectComponent.setProjects(project) />
		<cfset projectComponent = hibernate.save("jndiexample.data.Projectcomponents",projectComponent) >
		<cfif projectComponent.getComponentId() neq 0>
			<cfreturn "success">
		</cfif>
  </cffunction>

</cfcomponent>